package com.carlinfo.stu_ques.demo.service.impl;

import java.util.HashMap;
import java.util.List;


import java.util.Map;

import com.carlinfo.stu_ques.demo.dao.IDynastyDao;
import com.carlinfo.stu_ques.demo.dao.IKingDao;
import com.carlinfo.stu_ques.demo.dao.impl.DynastyDaoImpl;
import com.carlinfo.stu_ques.demo.dao.impl.KingDaoImpl;
import com.carlinfo.stu_ques.demo.pojo.Dynasty;
import com.carlinfo.stu_ques.demo.pojo.King;
import com.carlinfo.stu_ques.demo.service.IDemoService;

public class DemoServiceImpl implements IDemoService
{
	private IDynastyDao dynastyDao = new DynastyDaoImpl();
	

	@Override
	public int saveOneDynastyService(Dynasty dynasty)
	{
		int id = this.dynastyDao.saveOneDao(dynasty);
		return id;
	}

	@Override
	public void updateOneDynastyService(Dynasty dynasty)
	{
		this.dynastyDao.updateOneDao(dynasty);

	}

	@Override
	public void deleteOneDynastyService(Dynasty dynasty)
	{
		if(dynasty != null)
		{
			this.dynastyDao.deleteOneDao(dynasty);
		}else
		{
			System.out.println("===此条记录不存在===");
		}
		this.dynastyDao.deleteOneDao(dynasty);

	}

	@Override
	public List<Dynasty> selectListDynastyService()
	{
		return this.dynastyDao.selectListDao();
	}

	@Override
	public Dynasty selectOneDynastyService(Map<String, Object> condMap)
	{
		return this.dynastyDao.selectOneDao(condMap);
	}

	@Override
	public String printTitleDynastyService()
	{
		String result = "id\t名字\t首都\t年龄\t开过时间\t\t\t创建时间\t\t\t更新时间";
		return result;
	}
	/* 皇上的Demo实现类 */
	private IKingDao kingDao = new KingDaoImpl();

	@Override
	public int saveOneKingService(King king)
	{
		int id = this.kingDao.saveOneDao(king);
		return id;
	}

	@Override
	public void updateOneKingService(King king)
	{
		this.kingDao.updateOneDao(king);
	}

	@Override
	public void deleteOneKingService(King king)
	{
		this.kingDao.deleteOneDao(king);
	}

	@Override
	public List<King> selectListKingService()
	{
		List<King> kingList = this.kingDao.selectListDao();
		Map<String,Object> condMap = new HashMap<String,Object>();
		for(int i = 0; i < kingList.size() ; i ++)
		{
			King king = kingList.get(i);
			condMap.put("id",king.getDynasty());
			Dynasty dynasty = this.selectOneDynastyService(condMap);
			king.setDynasty(dynasty);
			
		}
		return kingList;
	}

	@Override
	public King selectOneKingService(Map<String, Object> condMap)
	{
		return this.kingDao.selectOneDao(condMap);
	}

	@Override
	public String printTitleKingService()
	{
		/**属性:id,朝代id,名字,年龄,身高,庙号,年号,创建时间,更新时间,*/
		String result = "id\t朝代id\t名字\t年龄\t身高\t庙号\t年号\t\t\t创建时间\t\t\t更新时间";
		return result;
	}

}
